package server

import (
	"gitee.com/tietang/terrace-go/v2/base"
	"github.com/apache/thrift/lib/go/thrift"
	log "github.com/sirupsen/logrus"
	"sync"
)

func init() {
	//glog.SetFlags(glog.Ldate | glog.Ltime | glog.Lmicroseconds | glog.Lshortfile)

}

var once sync.Once

type ThriftRpcServerStarter struct {
	base.BaseStarter
}

func (s *ThriftRpcServerStarter) Start(ctx base.StarterContext) {
	port := ctx.Props().GetDefault("app.rpc.port", "8970")
	protocolFactory := thrift.NewTCompactProtocolFactoryConf(nil)
	//protocolFactory := thrift.NewTBinaryProtocolFactoryConf(nil)
	cfg := &thrift.TConfiguration{}
	var transportFactory thrift.TTransportFactory
	transportFactory = thrift.NewTBufferedTransportFactory(8192)
	//transportFactory := thrift.NewTTransportFactory()
	transportFactory = thrift.NewTFramedTransportFactoryConf(transportFactory, cfg)
	err := runServer(transportFactory, protocolFactory, port, false)
	if err != nil {
		log.Error(err)
	}
}
func (s *ThriftRpcServerStarter) Priority() int { return 10000 }
